package cn.com.chifeng.dialogdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import cn.com.chifeng.dialogdemo.dialog.Effectstype;
import cn.com.chifeng.dialogdemo.dialog.NiftyDialogBuilder;

public class MainActivity extends AppCompatActivity {
//http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0812/1644.html
    private TextView tv;
     private Effectstype effect;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = (TextView) findViewById(R.id.tv);
        effect=Effectstype.Fadein;
        final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(this);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogBuilder
                        .withTitle("Modal Dialog")                                  //.withTitle(null)  no title
                        .withTitleColor("#FFFFFF")                                  //def
                        .withDividerColor("#11000000")                              //def
                        .withMessage("This is a modal Dialog.")                     //.withMessage(null)  no Msg
                        .withMessageColor("#FFFFFFFF")                              //def  | withMessageColor(int resid)
                        .withDialogColor("#FFE74C3C")                               //def  | withDialogColor(int resid)                               //def
                        .withIcon(getResources().getDrawable(R.mipmap.ic_launcher))
                        .isCancelableOnTouchOutside(true)                           //def    | isCancelable(true)
                        .withDuration(700)                                          //def
                        .withEffect(effect)                                         //def Effectstype.Slidetop
                        .withButton1Text("OK")                                      //def gone
                        .withButton2Text("Cancel")                                  //def gone
                        .setCustomView(R.layout.custom_view,view.getContext())         //.setCustomView(View or ResId,context)
                        .setButton1Click(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialogBuilder.dismiss();
                                Toast.makeText(v.getContext(), "i'm btn1", Toast.LENGTH_SHORT).show();
                            }
                        })
                        .setButton2Click(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialogBuilder.dismiss();
                                Toast.makeText(v.getContext(), "i'm btn2", Toast.LENGTH_SHORT).show();
                            }
                        })
                        .show();
            }
        });
    }
}
